package pl.gigiel.behaviour.util;

import java.util.Random;

import pl.gigiel.behaviour.IBoid;

import com.jme.math.Vector3f;

public class Util {
	private static Random random = new Random(System.currentTimeMillis());

	public static float random(float min, float max) {
		float result = 0;
		float difference = max - min;
		result = min + difference * random.nextFloat();
		return result;
	}

	public static void checkNaN(Vector3f vector) {
		if (Float.isNaN(vector.x) || Float.isNaN(vector.y) || Float.isNaN(vector.z)) {
			throw new IllegalArgumentException("vector is NaN");
		}
	}

	public static Vector3f truncatedMutual(Vector3f vector, float absLengthMax) {
		Vector3f result = new Vector3f(vector);
		result.x = truncated(result.x, -absLengthMax, absLengthMax);
		result.y = truncated(result.y, -absLengthMax, absLengthMax);
		result.z = truncated(result.z, -absLengthMax, absLengthMax);
		if (result.length() > absLengthMax) {
			result.normalizeLocal();
			result.multLocal(absLengthMax);
		}
		return result;
	}

	public static float truncated(float a, float min, float max) {
		float result;
		result = a < min ? min : a;
		result = a > max ? max : a;
		return result;
	}

	public static float distance(IBoid a, IBoid b) {
		float distance = 0f;
		Vector3f positionA = a.getFeatures().getPosition();
		Vector3f positionB = b.getFeatures().getPosition();
		Vector3f offset = positionA.subtract(positionB);
		distance = offset.length();
		return distance;
	}

	public static boolean isEmpty(Vector3f vector) {
		boolean result = (vector == null) || (vector.length() == 0);
		return result;
	}

	public static int beyond(float centreA, float diameterA, float centreB, float diameterB) {
		float radiusA = diameterA / 2.0f;
		float radiusB = diameterB / 2.0f;

		return 0;
	}

	public static Vector3f cloneVector(Vector3f vector) {
		Vector3f result = null;
		if (vector != null) {
			result = new Vector3f(vector);
		}
		return result;
	}
}
